package rlm.rlcontainer;

import alm.XTab;
import alm.YTab;

public class VerticalPlaceHolder extends BiPartitionPlaceHolder<XTab> {

	public VerticalPlaceHolder(PlaceHolder a, PlaceHolder b) {
		super(a, b);
	}
	
	protected void addInnerRelation(){
		getLeftPlace().addRight(getRightPlace());
		getRightPlace().addLeft(getLeftPlace());
	}
	
	public PlaceHolder getLeftPlace(){
		return this.get0();
	}
	
	public PlaceHolder getRightPlace(){
		return this.get1();
	}


	@Override
	public PlaceHolder addBottom(PlaceHolder p) {
		p.addTop(this);
		getLeftPlace().addBottom(p);
		getRightPlace().addBottom(p);
		return p;
	}


	@Override
	public PlaceHolder addLeft(PlaceHolder p) {
		getLeftPlace().addLeft(p);
		return p;
	}


	@Override
	public PlaceHolder addRight(PlaceHolder p) {
		getRightPlace().addRight(p);
		return p;
	}


	@Override
	public PlaceHolder addTop(PlaceHolder p) {
		getRightPlace().addTop(p);
		getLeftPlace().addTop(p);
		return p;
	}

	//----------------------------
	// Tabs
	//----------------------------
	
	@Override
	public void setBottomTab(YTab bottomTab) {
		super.setBottomTab(bottomTab); // needed??
		get0().setBottomTab(bottomTab);
		get1().setBottomTab(bottomTab);
	}

	@Override
	public void setLeftTab(XTab leftTab) {
		// TODO Auto-generated method stub
		super.setLeftTab(leftTab);
	}

	@Override
	public void setRightTab(XTab rightTab) {
		super.setRightTab(rightTab);
		this.getRightPlace().setRightTab(rightTab);
	}

	@Override
	public void setTopTab(YTab topTab) {
		super.setTopTab(topTab);
		getRightPlace().setTopTab(topTab);
		getLeftPlace().setTopTab(topTab);
	}

	// ----------
	// inner tab
	// -----------
	@Override
	public void setInnerTab(XTab tab) {
		super.setInnerTab(tab);
		getLeftPlace().setRightTab(tab);
		getRightPlace().setLeftTab(tab);
	}
	
	public int getXCount(){
		return getRightPlace().getXCount() + getLeftPlace().getXCount();
	}
	
	public int getYCount(){
		return Math.max(getRightPlace().getYCount(), getLeftPlace().getYCount());
	}
	
}
